//按钮弹起时发送请求，根据关键字去查询应急调查点
function getYJDCDByKeyword(){
	var lyCode = $("#userXZQLabel").text();
	lyCode = handleXZQCode(lyCode);
	var keyword = $("#yjdcdNameInput").val();
	if(keyword!=""){
		var url = "queryYJDCDByKeyWord.shtml";
		var obj = {lyCode:lyCode,keyword:keyword};
		$.post(url,obj,getYJDCDCallback);
	}
}

//按钮弹起之后的回调
function getYJDCDCallback(res){
	if(res!=""){
		res = eval(res);
		$("#inputResDiv").html("");
		for(var i = 0;i<res.length;i++){
			var biaoshi = res[i].biaoshi;
			var type = getOperTypeZhdByCode(biaoshi);
			var str = '<div id="'+i+'" class="resLiDiv" style="cursor:pointer;margin-bottom:3px;border-bottom:1px dashed black;width:98%;height:14px;line-height:14px;font-family:微软雅黑;font-size:11px;">'+res[i].name+'('+type+')'+'</div>';
			$("#inputResDiv").append(str);
		}
		$("#inputResDiv").show();
		//点击某个
		$(".resLiDiv").click(function(evt){
			var index = $(this)[0].id;
			var name = res[index].name;
			$("#yjdcdNameInput").val(name);
			$("#yjdcdNameInput").attr("title",res[index].id+"&"+res[index].biaoshi);
			$("#inputResDiv").hide();
		})
	}
}

//处理行政区，进行权限的查询
function handleXZQCode(areaCode){
	var code = "000000";
	if(areaCode.length==6){
		if(areaCode.substring(2, 6)=="0000"){
			code = areaCode.substring(0, 2);
			code  = code +"__________";
		}else if(areaCode.substring(4,6)=="00"){
			code = areaCode.substring(0, 4);
			code = code+"________";
		}else{
			code = areaCode;
			code = code +"______";
		}
	}
	return code;
}

function getOperTypeZhdByCode(code){
	var type = "十万调查点";
	switch(code){
	case "1": type = "十万调查点";break;
	case "2": type = "五万调查点";break;
	case "3": type = "应急调查点";break;
	case "4": type = "群测群防点";break;
	case "5": type = "重大灾害点";break;
	case "6": type = "应急监测点";break;
	case "new": type="新增点";break;
	}
	return type;
}

/////////////////////////////////点击提交按钮,向本机插入基本调查信息//////////////////////////////////
function submitClickFunc(){
	if($("#yjdcdNameInput").val()==""||$("#dcsjInput").val()==""){
		alert("调查点或调查时间必须填写");
		return;
	}
	insertBenji();
}

//插入本机的数据库
function insertBenji(){
	var yjdc01000Str = $("#yjdcdNameInput").attr("title");
	if(yjdc01000Str==undefined){
		alert("您选择的点可能是缓存，请重新在文本框输入重新选择!");
		return;
	}
	if($("#yjdcdjingdu").val()==""||$("#yjdcdweidu").val()==""){
		alert("请您必须填写经纬度!");
		return;
	}
	var jbqk0110 = $("#yjdcdNameInput").val();
	var yjdc01000 = yjdc01000Str.split("&")[0];
	var jbqk0102 = yjdc01000Str.split("&")[1];
	var yjdc01140Array = $("input[name=rggcyfys]:checked");
	var yjdc01140 = "";
	if(yjdc01140Array.length>0){
		for(var i = 0;i<yjdc01140Array.length-1;i++){
			yjdc01140 = yjdc01140 + yjdc01140Array[i].value +",";
		}
		yjdc01140 = yjdc01140 + yjdc01140Array[yjdc01140Array.length-1].value;
	}
	var yjdc01330Array = $("input[name=xcclyj]:checked");
	var yjdc01330 = "";
	if(yjdc01330Array.length>0){
		for(var j = 0;j<yjdc01330Array.length-1;j++){
			yjdc01330 = yjdc01330 + yjdc01330Array[j].value +",";
		}
		yjdc01330 = yjdc01330 + yjdc01330Array[yjdc01330Array.length-1].value;
	}
	$("#yjdclrForm").attr("action","insertYjdcdForFWQ.shtml?jbqk0110="+jbqk0110+"&jbqk0102="+jbqk0102+"&yjdc01000="+yjdc01000+"&yjdc01140="+yjdc01140+"&yjdc01330="+yjdc01330);
	$("#yjdclrForm").submit(function () {
        // 提交表单
        $(this).ajaxSubmit();
        // 为了防止普通浏览器进行表单提交和产生页面导航（防止页面刷新？）返回false
        return false;
    });
    $("#yjdclrForm").ajaxSubmit(function (res) {
    	if(res.length>4){
   		 	//内容的转化（内容有标签时），防止谷歌对jquery的返回对象不同
     		var hiddenDiv = $("<div>");
     		hiddenDiv.html(res);
     		res = hiddenDiv.text();
   		}
    	if(res=="true"){
    		alert("插入成功!");
    	}else{
    		alert("插入失败！");
    	}
    });
}